<?php
class Log {

	private static $log	= array();
	private static $id	= null;

	const EMERG		= 0; /** System is unusable */
	const ALERT		= 1; /** Immediate action required */
	const CRIT		= 2; /** Critical conditions */
	const ERR		= 3; /** Error conditions */
	const WARNING	= 4; /** Warning conditions */
	const NOTICE	= 5; /** Normal but significant */
	const INFO		= 6; /** Informational */
	const DEBUG		= 7; /** Debug-level messages */

	public function __construct() {
		if (self::$id === null) {
			self::$id = md5(microtime(true));
		}
	}
	
	public static function getId() {
		return self::$id; 
	}

	public static function write($message, $level = self::DEBUG) {
		$config = new Config;
		$level = self::__levelToString($level);
		self::$log[] = sprintf($config->logLineFormate, date($config->logTimeFormate), $level, $message);
	}

	public static function __levelToString($level) {
		//@TODO I18n
		$levels = array("System is unusable",
				"Immediate action required",
				"Critical conditions",
				"Error conditions",
				"Warning conditions",
				"Normal but significant",
				"Informational",
				"Debug-level messages"
			);
		return (string) $levels[$level];
	}
	
	public static function getLog() {
		return self::$log;
	}
	
	public static function toString() {
		return (string) implode("", self::$log);
	}

}